<html>
<head>
<link type="text/css" rel="stylesheet" href="nerd.css">
</head>
<body class="background_img" background="./img/sfondo/gaming.jpg">


<?php


/*
@package Achievement Chart
@version 1.0
@Copyright (c) 2010-2011 Bovy
@license http://opensource.org/licenses/gpl-license.php GNU Public License


This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


@include("configuration.php");

/* use configuration.xml file


$host = $conf["host"];
$user = $conf["user"]; 
$pass = $conf["pass"]; 
$characters_db = $conf["characters_db"]; 
$achi_db_table = $conf["achi_db_table"]; 
$char_achi_table = $conf["char_achi_table"]; 

$pathtopg = $conf["url"]; 
$pathtoguild = $conf["gilda"]; 
$num_limit = $conf["limit"];  */

mysql_connect($host,$user,$pass);

echo "<h2 style='text-align:center; color:white;'>Achievement Point Chart";


@mysql_select_db($characters_db) or die ("Connection to database, FAILED");

$query_for_armory = 'search.xml?searchQuery=';
$query_for_armory1 = '&searchType=all';



$query="select c.guid from $char_achi_table c JOIN $achi_db_table a  on (c.achievement=a.achievement) group by guid order by sum(a.points) desc limit $num_limit";
$query2="select sum(a.points) from $char_achi_table c JOIN $achi_db_table a  on (c.achievement=a.achievement) group by guid order by sum(a.points) desc limit $num_limit";

$result=mysql_query($query);
$result2=mysql_query($query2);

$count=0;

echo "<p><table align=center border=1 width=55%>";

echo "<tr><td class=first>Pos:<td class=first>Character<td class=first>Faction<td 
class=first>Race<td class=first>Class<td class=first>Level<td class=first>Achievement Point<td class=first>Guild";



while($row2 = mysql_fetch_array($result2, MYSQL_NUM)){
echo "<tr>";

echo "<td class=num>";
$count=$count+1;
printf("%s", $count);

$row = mysql_fetch_array($result, MYSQL_NUM);


$result3=mysql_query("SELECT name,level,gender,race,class FROM characters WHERE guid='$row[0]'");

$result4=mysql_query("SELECT name FROM guild WHERE guildid=(SELECT guildid FROM guild_member WHERE guid='$row[0]')");

$asd=mysql_fetch_object($result3);

$guild=mysql_fetch_object($result4);


/*printf("%s", $asd->name);*/
$newname = $asd->name;

echo "<td class=name><a class=link_armory href=$pathtopg$query_for_armory$newname$query_for_armory1>$newname</a>";

echo "<td class=faction>";

switch ($asd->race){

case 1: 
case 3: 
case 4: 
case 7: 
case 11: print "<img src='./img/ally.gif'>"; break;
case 5: 
case 6: 
case 8: 
case 2: 
case 10: print "<img src='./img/horde.gif'>"; break;


}

echo "<td class=race>";

switch ($asd->race){

case 1: if($asd->gender == 0) {

		echo "<img src='./img/human.gif'>"; break;

			}else{
				echo "<img src='./img/human_female.gif'>"; break;
				}

case 2: if($asd->gender == 0) {

		echo "<img src='./img/orc.gif'>"; break;

			}else{
				echo "<img src='./img/orc_female.gif'>"; break;
				}
case 3: if($asd->gender == 0) {

		echo "<img src='./img/dwarf.gif'>"; break;

			}else{
				echo "<img src='./img/dwarf _female.gif'>"; break;
				}
case 4: if($asd->gender == 0) {

		echo "<img src='./img/nightelf.gif'>"; break;

			}else{
				echo "<img src='./img/nightelf_female.gif'>"; break;
				}
case 5: if($asd->gender == 0) {

		echo "<img src='./img/undead.gif'>"; break;

			}else{
				echo "<img src='./img/undead_female.gif'>"; break;
				}
case 6: if($asd->gender == 0) {

		echo "<img src='./img/tauren.gif'>"; break;

			}else{
				echo "<img src='./img/tauren_female.gif'>"; break;
				}
case 7: if($asd->gender == 0) {

		echo "<img src='./img/gnome.gif'>"; break;

			}else{
				echo "<img src='./img/gnome_female.gif'>"; break;
				}
case 8: if($asd->gender == 0) {

		echo "<img src='./img/troll.gif'>"; break;

			}else{
				echo "<img src='./img/troll_female.gif'>"; break;
				}
case 10: if($asd->gender == 0) {

		echo "<img src='./img/bloodelf.gif'>"; break;

			}else{
				echo "<img src='./img/bloodelf_female.gif'>"; break;
				}
case 11: if($asd->gender == 0) {

		echo "<img src='./img/draenei.gif'>"; break;

			}else{
				echo "<img src='./img/draenei_female.gif'>"; break;
				}

}

echo "<td class=classe>";

switch ($asd->class){

case 1: echo "<img src='./img/warrior.gif'>"; break;
case 2: echo "<img src='./img/paladin.gif'>"; break;
case 3: echo "<img src='./img/hunter.gif'>"; break;
case 4: echo "<img src='./img/rogue.gif'>"; break;
case 5: echo "<img src='./img/priest.gif'>"; break;
case 6: echo "<img src='./img/dk.gif'>"; break;
case 7: echo "<img src='./img/shaman.gif'>"; break;
case 8: echo "<img src='./img/mage.gif'>"; break;
case 9: echo "<img src='./img/warlock.gif'>"; break;
case 11: echo "<img src='./img/druid.gif'>"; break;

}

echo "<td class=level>"; 
printf("%s", $asd->level);


echo "<td class=nerd>";
printf("%s", $row2[0]);

//echo "<td class=guild>";
//printf("%s", $guild->name);

$newguild = $guild->name;
echo "<td class=guild><a class=link_armory href=$pathtoguild$query_for_armory$newguild$query_for_armory1>$newguild</a>";




}


?>
</body>
</html>
